package com.ruoyi.key.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.key.domain.KeyStudent;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.key.domain.TbKeyallocation;
import com.ruoyi.key.service.ITbKeyallocationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索分配Controller
 * 
 * @author ruoyi
 * @date 2025-06-25
 */
@RestController
@RequestMapping("/keyallocation/keyallocation")
public class TbKeyallocationController extends BaseController
{
    @Autowired
    private ITbKeyallocationService tbKeyallocationService;

    /**
     * 查询线索分配列表
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:list')")
    @GetMapping("/list")
    public TableDataInfo list(KeyStudent tbKeyallocation)
    {
        startPage();
       List<KeyStudent> list = tbKeyallocationService.selectKeyStudentList(tbKeyallocation);
        System.out.println("1111111111111111"+list);
        return getDataTable(list);
    }

    /**
     * 导出线索分配列表
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:export')")
    @Log(title = "线索分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbKeyallocation tbKeyallocation)
    {
        List<TbKeyallocation> list = tbKeyallocationService.selectTbKeyallocationList(tbKeyallocation);
        ExcelUtil<TbKeyallocation> util = new ExcelUtil<TbKeyallocation>(TbKeyallocation.class);
        util.exportExcel(response, list, "线索分配数据");
    }

    /**
     * 获取线索分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:query')")
    @GetMapping(value = "/{allocationId}")
    public AjaxResult getInfo(@PathVariable("allocationId") Long allocationId)
    {
        return success(tbKeyallocationService.selectTbKeyallocationByAllocationId(allocationId));
    }

    /**
     * 新增线索分配
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:add')")
    @Log(title = "线索分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbKeyallocation tbKeyallocation)
    {
        System.out.println("+++++"+tbKeyallocation);
        return toAjax(tbKeyallocationService.insertTbKeyallocation(tbKeyallocation));
    }

    /**
     * 修改线索分配
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:edit')")
    @Log(title = "线索分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbKeyallocation tbKeyallocation)
    {
        System.out.println("+++++"+tbKeyallocation);
        return toAjax(tbKeyallocationService.updateTbKeyallocation(tbKeyallocation));
    }

    /**
     * 删除线索分配
     */
    @PreAuthorize("@ss.hasPermi('keyallocation:keyallocation:remove')")
    @Log(title = "线索分配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{allocationIds}")
    public AjaxResult remove(@PathVariable Long[] allocationIds)
    {
        return toAjax(tbKeyallocationService.deleteTbKeyallocationByAllocationIds(allocationIds));
    }
}
